#include <bits/stdc++.h>

using namespace std;
using ll = long long;
#define int long long
const int inf = 0x3f3f3f3f;

bool compare(const pair<string, string>& p1, const pair<string, string>& p2)
{
    return p1.second < p2.second;
}

void solve()
{
    int n;
    cin >> n;
    vector<pair<string, string>> a(n);
    for (int i = 0; i < n; i++) cin >> a[i].first >> a[i].second;
    sort(a.begin(), a.end(), compare);
    int ans = 1;
    pair<string, string> now = a[0];
    for (int i = 1; i < n; i++)
    {
        if (a[i].first >= now.second)
        {
            ans++;
            now = a[i];
        }
    }
    cout << ans;
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int _ = 1;
    //cin >> _;
    while (_--)
    {
        solve();
    }
    return 0;
}